package com.xl.flinkdemo.source;

import com.xl.flinkdemo.beans.SensorReding;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @ClassName SourceTest_Collecttion
 * @Description TODO
 * @Author hxl
 * @Date 2021/4/14 15:08
 * Version 1.0
 **/
public class SourceTest_Collecttion {

  public static void main(String[] args) throws Exception {
    //创建执行环境
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    //从集合中读取数据
    DataStream<SensorReding> dataStream = env.fromCollection(Arrays.asList(
        new SensorReding("sensor_1", 154771899L, 35.8),
        new SensorReding("sensor_2", 154771901L, 36.8),
        new SensorReding("sensor_3", 154771902L, 33.8),
        new SensorReding("sensor_4", 154771903L, 31.8)));

//    env.fromElements()
    DataStreamSource<Integer> integerDataStream = env.fromElements(1, 2, 434, 545);
    //打印输出
    //发现，顺序是错乱的哦
    dataStream.print("dataStream输出");
    integerDataStream.print("integerDataStream输出");

    //执行
    env.execute("jobName_TestSourceJob");
  }

}
